<?php

namespace App\Support;

use Carbon\Carbon;

class Support
{

    /**
     * 返回某一年的开始时间和结束时间.
     *
     * @param $year
     * @param string $field
     *
     * @return string
     */
    public static function makeYearDate($year, string $field = 'from'): string
    {
        $from = date('Y-m-d', mktime(0, 0, 0, 1, 1, $year));
        $to = date('Y-m-d', mktime(23, 59, 59, 12, 31, $year));
        if ($field == 'to') {
            return $to;
        }

        return $from;
    }

    public static function getYearMonthDay($datetime)
    {
        $year = Carbon::createFromFormat('Y-m-d H:i:s', $datetime)->year;
        $month = Carbon::createFromFormat('Y-m-d H:i:s', $datetime)->month;
        $day = Carbon::createFromFormat('Y-m-d H:i:s', $datetime)->day;
        return ['year' => $year, 'month' => $month, 'day' => $day];
    }
}
